
Ext.User = Ext.extend(Ext.Button,{
			render:function(container,pos){
				this.setText('账户');//设置按钮文字
				/*按钮处理函数*/
				this.addListener('click',function(){
					var t = this.initialConfig.e;
					Ext.User.doView(t);
				});
				Ext.User .superclass.render.apply(this, arguments);
			}});
//do 查询
Ext.User.doQuery=function(name,store){
	var t = {name:name};
	//dwrFunctionArgs
	store.load({params:{start:0,limit:20}});
}
//传入text 框
Ext.User.doView=function(t){
	var type = t.getEl().getAttributeNS('','paramType');
	var mul = (type==1);
	//运行时参数
	var sm = new Ext.grid.RowSelectionModel({singleSelect:!mul});
		var proxy = new Ext.ux.data.DWRProxy({dwrFunction:UserService.getUserlist});
		var store =  new Ext.data.JsonStore({
			proxy:proxy,
			totalProperty:'count',
			root:'res',
	        fields: ['name']
	    });
		//
		
		var nameText = new Ext.form.TextField();
		
		var queryBt = new Ext.Button({text:'查询',handler:function(){
			Ext.User.doQuery(nameText.getValue(),store);
		}});
		
		var pager = new Ext.PagingToolbar({pageSize:20,store:store,displayInfo:true});
		//
		store.on('beforeload',function(s,ops){
			
			var start = ops.params['start'];
			var limit = ops.params['limit'];
			var pageNo = Math.ceil((start+limit)/limit);
			var t = {name:nameText.getValue()};
			ops.params['dwrFunctionArgs']=[t,pageNo,limit];
		});
		
		var grid = new Ext.grid.GridPanel({
		    store:store,
		    columns: [
		        {header: "账户名", width: 120, sortable: true, dataIndex: 'name'}
		    ],
		    
		    viewConfig: {
		        forceFit: true
		    },
		    sm: sm,
		    width:600,
		    height:300,
		    frame:true,
		    title:''
		});
		
		var win = new Ext.Window({
				title:'账户列表',
				width:600,
				height:360,
				layout:'border',
				closable:false,
				modal:true,
				items:[{region:'north',height:30,items:[{layout:'table',items:[new Ext.form.Label({text:'账户名:'}),nameText,queryBt]}]},
				       {region:'center',items:[grid]},
				       {region:'south',height:30,items:[pager]}],
				buttons:[{text:'确定',handler:function(){
					 var rec = sm.getSelections();
					 if (!rec || rec.length <= 0){
						 
						 alert("必须选择一个");
						 return;
					 }
					 //编码数据
					 var retVal = '';
					 for (var i = 0 ; i < rec.length;i++){
						 var val = rec[i].get('name');
						 retVal=retVal+','+val;
					 }
						t.setValue(retVal.substr(1));
						win.close();
					}},{
						text:'取消',handler:function(){
						win.close();
						
						}
					}]
		   });
		  win.show();	
		  store.load({params:{start:0,limit:20}});
}